#pragma once

#include <iostream>
#include <string>

using namespace std;

//运算符
string oper = "+-*/%";

enum
{   
    //除0错误
    DivError = 1,
    //模0错误
    ModError,
    //操作符未知
    UnKnown
};

class Task
{
public:
    Task(int x, int y, char op)
        : _data1(x)
        , _data2(y)
        , _oper(op)
        , _result(0)
        , _exitcode(0)
    {
    }
    void run()
    {
        switch (_oper)
        {
        case '+':
            _result = _data1 + _data2;
            break;
        case '-':
            _result = _data1 - _data2;
            break;
        case '*':
            _result = _data1 * _data2;
            break;
        case '/':
        {
            if (_data2 == 0)
                _exitcode = DivError;
            else 
                _result = _data1 / _data2;
        }
            break;
        case '%':
        {
            if (_data2 == 0)
                _exitcode = ModError;
            else 
                _result = _data1 % _data2;
        }
            break;
        default:
            _exitcode = UnKnown;
            break;
        }
    }

    //获取结果
    string GetResult()
    {
        string r = to_string(_data1);
        r += _oper;
        r += to_string(_data2);
        r += '=';
        r += to_string(_result);
        r += "[exitcode:";
        r += to_string(_exitcode);
        r += ']';

        return r;
    }

    //获取任务
    string GetTask()
    {
        string r = to_string(_data1);
        r += _oper;
        r += to_string(_data2);
        r += '=';

        return r;        
    }

    ~Task()
    {}

private:
    int _data1;
    int _data2;
    char _oper;

    //结果
    int _result;
    //设置退出码,
    int _exitcode;
};